import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { PartsRequipmentVO, PartsRequipmentForm, PartsRequipmentQuery } from '@/api/workorder/partsRequipment/types';
import { Accessory } from '@/api/workorder/workorderInfo/types';

/**
 * 查询备件需求列表
 * @param query
 * @returns {*}
 */

export const listPartsRequipment = (query?: PartsRequipmentQuery): AxiosPromise<PartsRequipmentVO[]> => {
  return request({
    url: '/workorder/partsRequipment/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询备件需求详细
 * @param id
 */
export const getPartsRequipment = (id: string | number): AxiosPromise<PartsRequipmentVO> => {
  return request({
    url: '/workorder/partsRequipment/' + id,
    method: 'get'
  });
};

/**
 * 新增备件需求
 * @param data
 */
export const addPartsRequipment = (data: PartsRequipmentForm) => {
  return request({
    url: '/workorder/partsRequipment',
    method: 'post',
    data: data
  });
};

/**
 * 修改备件需求
 * @param data
 */
export const updatePartsRequipment = (data: PartsRequipmentForm) => {
  return request({
    url: '/workorder/partsRequipment',
    method: 'put',
    data: data
  });
};

/**
 * 删除备件需求
 * @param id
 */
export const delPartsRequipment = (id: string | number | Array<string | number>) => {
  return request({
    url: '/workorder/partsRequipment/' + id,
    method: 'delete'
  });
};
export const addWorkorderPartsBatch = (accessories: Accessory[]) => {
  return request({
    url: '/workorder/partsRequipment/submitWorkorderParts2partsRequipment',
    method: 'post',
    data: accessories
  });
};

/**
 * 来源保存
 * @param data
 */
export const partsRequipmentSave = (data: PartsRequipmentForm) => {
  return request({
    url: '/workorder//partsRequipment/save',
    method: 'post',
    data: data
  });
};

export const execReceipt = (id: string | number): AxiosPromise<PartsRequipmentVO> => {
  return request({
    url: '/workorder//partsRequipment/receipt/' + id,
    method: 'get'
  });
};
